package cn.buk.qms.entity;

import cn.buk.tms.dto.TrainOrderDto;
import cn.buk.tms.dto.TrainOrderPassengerDto;
import cn.buk.common.util.DateUtil;
import cn.buk.tms.entity.misc.*;
import cn.buk.tms.entity.order.flight.FlightOrder;
import cn.buk.tms.entity.order.flight.FlightOrderFlight;
import cn.buk.tms.entity.order.flight.FlightOrderPassenger;
import cn.buk.tms.entity.order.hotel.HotelOrder;
import cn.buk.tms.entity.order.train.TrainOrder;
import cn.buk.tms.entity.order.train.TrainOrderPassenger;

import java.text.ParseException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public final class EntitiesHelper {
	
	public static final int ERRORCODE_NO_ENTERPRISE = -10004; 
	
	public static final int USER_ID = 666;
	public static final String USER_USERNAME = "test2013";
	public static final String USER_EMPNAME = "william/dai";
	public static final String USER_IS_ADMIN = "0";
	public static final String USER_EMAIL = "yfdai@buk.cn";
	public static final String USER_EXPIRE_DATE = "2015-12-31";
	
	
	public static final String PNR_PNRNO = "TEST01";
	
	public static final int CUSTOMER_ENTERPRISE_ID = 112;
	public static final String CUSTOMER_VIP_NAME = "IBM Shanghai";

    public static final String CUSTOMER_DEPARTMENT_CODE = "D001";
    public static final String CUSTOMER_DEPARTMENT_NAME = "IT Department";

	public static final int ENTERPRISE_ID = 22;
	public static final int ENTERPRISE_ID_UNKNOWN = 999;
	public static final String ENTERPRISE_NAME="buk.cn";
	public static final int ENTERPRISE_USERCOUNT = 3;

    public static final String PASSENGER_NAME_CN ="daiyunfeng".toUpperCase();
    public static final String PASSENGER_NAME_EN = "yunfeng/dai";
    public static final String PASSENGER_ID_NO = "310101198808082810";
    public static final String PASSENGER_PASSPORT_NO = "P89999";
	
	public static final String ORDER_BILL_NO = "1099";
	
	public static final String DETR_TICKETNO = "999l023456789";
	
	public static final String GROUP_NAME = "GroupTestA";

	public static final String FLIGHT_ORDER_NO = "1001111";

	private EntitiesHelper() {
	    throw new UnsupportedOperationException("this class is a helper");
	}
	
	  public static User newUser()  {
		    User user = new User();
		    user.setUsername(USER_USERNAME);
		    user.setEmpname(USER_EMPNAME);
		    user.setIsadmin(USER_IS_ADMIN);
		    user.setEmail(USER_EMAIL);
            user.setCreateTime(DateUtil.createDate(2014,1,1));
		    try {
				user.setExpireDate(DateUtil.convertToDate(USER_EXPIRE_DATE));
			} catch (ParseException e) {
				e.printStackTrace();
			}

		    return user;
		  }	  
	  
	  public static User newUserWithId() {
		  User user = newUser();
		  user.setId(USER_ID);
		  return user;
	  }
	  
	  public static User newUserBelongToEnterprise() {
		  User user = newUser();
		  Enterprise enterprise = newEnterprise();
		  
		  user.setEnterprise(enterprise);
		  
		  return user;
	  }
	  
	  public static User newUserBelongToEnterpriseWithId() {
		  User user = newUserBelongToEnterprise();
		  user.setId(USER_ID);
		  
		  return user;
	  }
 
	  
	  public static void assertUser(User user) {
//		    assertNotNull("object must be not null", user);
		    assertEquals(USER_USERNAME, user.getUsername());
		    assertEquals(USER_EMPNAME, user.getEmpname());
		    assertEquals(USER_EMAIL, user.getEmail());
		    assertEquals(USER_IS_ADMIN, user.getIsadmin());
		  }	 
	  
	  public static User newUserWithEnterprise() {
		  User user = newUser();
		  Enterprise enterprise = newEnterprise();
		  user.setEnterprise(enterprise);
		  
		  return user;
	  }
	  
	  public static Pnr newPnr() {
		  Pnr pnr = new Pnr();
		  pnr.setPnrNo(PNR_PNRNO);
		  pnr.setEnterpriseId(ENTERPRISE_ID);
		  
		  PnrFlight flight1 = new PnrFlight();
		  flight1.setPnr(pnr);
		  flight1.setSn(1);
		  pnr.getFlights().add(flight1);
		  
		  PnrFlight flight2 = new PnrFlight();
		  flight2.setPnr(pnr);
		  flight2.setSn(2);
		  pnr.getFlights().add(flight2);
		  
		  PnrFlight flight3 = new PnrFlight();
		  flight3.setPnr(pnr);
		  flight3.setSn(3);
		  pnr.getFlights().add(flight3);
		  
		  
		  
		  return pnr;
	  }
	  
	  public static void assertPnr(Pnr pnr) {
//		  assertNotNull("object pnr must be not null", pnr);
		  assertEquals(PNR_PNRNO, pnr.getPnrNo());
	  }
	  
	  public static Customer newCustomer() {
		  Customer customer = new Customer();
		  
		  customer.setEnterpriseId(ENTERPRISE_ID);
		  customer.setCustomerEnterpriseId(CUSTOMER_ENTERPRISE_ID);
		  customer.setVipName(CUSTOMER_VIP_NAME);
		  
		  return customer;	  
	  }
	  
	  public static void assertCustomer(Customer customer) {
//		  assertNotNull("object customer must be not null", customer);
		  assertEquals(ENTERPRISE_ID, customer.getEnterpriseId());
		  assertEquals(CUSTOMER_ENTERPRISE_ID, customer.getCustomerEnterpriseId());
		  assertEquals(CUSTOMER_VIP_NAME, customer.getVipName());
	  }
	  
	  public static Enterprise newEnterprise() {
		  Enterprise enterprise = new Enterprise();
		  enterprise.setId(ENTERPRISE_ID);
		  enterprise.setName(ENTERPRISE_NAME);
		  enterprise.setUserCount(ENTERPRISE_USERCOUNT);
		  return enterprise;
	  }
	  
	  public static void assertEnterprise(Enterprise enterprise) {
//		  assertNotNull("object enterprise must be not null", enterprise);
		  assertEquals(ENTERPRISE_ID, enterprise.getId());
		  assertEquals(ENTERPRISE_NAME, enterprise.getName());
	  }
	  
	  public static DetrInfo newDetr() {
		  DetrInfo detr = new DetrInfo();
		  
		  detr.setEnterpriseId(ENTERPRISE_ID);
		  detr.setTicketNo(DETR_TICKETNO);
		  
		  return detr;
	  }
	  
	  public static void assertDetr(DetrInfo detr) {
//		  assertNotNull("Object detr must be not null", detr);
		  assertEquals(ENTERPRISE_ID, detr.getEnterpriseId());
		  assertEquals(DETR_TICKETNO, detr.getTicketNo());
	  }
	  
    public static Passenger newPassenger() {
        Passenger passenger = new Passenger();

        passenger.setEnterpriseId(ENTERPRISE_ID);
//        passenger.setVipCode(CUSTOMER_VIP_CODE);
        passenger.setNameCn(PASSENGER_NAME_CN);
        passenger.setNameEn(PASSENGER_NAME_EN);
        passenger.setIdNo(PASSENGER_ID_NO);
        passenger.setPassportNo(PASSENGER_PASSPORT_NO);

        return passenger;
    }

    public static void assertPassenger(Passenger passenger) {
//        assertNotNull("Object passenger must be not null.", passenger);
        assertEquals(ENTERPRISE_ID, passenger.getEnterpriseId());
//        assertEquals(CUSTOMER_VIP_CODE, passenger.getVipCode());
        assertEquals(PASSENGER_NAME_CN, passenger.getNameCn());
        assertEquals(PASSENGER_NAME_EN, passenger.getNameEn());
        assertEquals(PASSENGER_ID_NO, passenger.getIdNo());
        assertEquals(PASSENGER_PASSPORT_NO, passenger.getPassportNo());
    }

    public static Product newProduct() {
        Product product = new Product();
        product.setProductCode("P001");
        product.setProductName("Itinerary Print");
        product.setChargeUnit(0);
        product.setRetailPrice(1000);

        return product;
    }

    public static ProductBought newProductBought() {
        ProductBought productBought = new ProductBought();

        productBought.setEnterpriseId(2);
        productBought.setEndTime(DateUtil.createDate(2014,12,28));
        productBought.setBoughtCount(0);
        productBought.setChargeUnit(0);

        return productBought;
    }


    //火车票订单
	public static TrainOrder createTrainOrder() {
		TrainOrder o = new TrainOrder();

		o.setEnterpriseId(ENTERPRISE_ID);

		o.setOrderNo("123456");
		o.setExternalOrderNo("ED39815455");
		o.setTrainNo("K123");
		o.setSeatClass("二");
		o.setDcity("上海虹桥");
		o.setAcity("北京西");
		o.setDdate(DateUtil.createDate(2018, 12, 29));

		o.setCustomerId(0); //散客
		o.setOperator("op1");

		TrainOrderPassenger psg = new TrainOrderPassenger();
		psg.setName("WILLIAM/DAI");
		psg.setIdType(1);
		psg.setIdNo("360403");
		psg.setCoachNo("3");
		psg.setSeatNo("12F");
		psg.setMobile("15618206323");



		o.getPassengers().add(psg);

		psg = new TrainOrderPassenger();
		psg.setName("CICI/WANG");

		o.getPassengers().add(psg);

		return o;
	}

	public static TrainOrderDto createTrainOrderDto() {
		TrainOrderDto dto = new TrainOrderDto();
		dto.setOrderNo("123456");
		dto.setExternalOrderNo("ED39815455");
		dto.setTrainNo("K123");
		dto.setSeatClass("二");
		dto.setDcity("上海虹桥");
		dto.setAcity("北京西");
		dto.setDdate(DateUtil.createDate(2018, 12, 29));

		dto.setCustomerId(0); //散客
		dto.setOperator("op1");



		TrainOrderPassengerDto psgDto = new TrainOrderPassengerDto();
		psgDto.setName("WILLIAM/DAI");
		psgDto.setIdType(1);
		psgDto.setIdNo("360403");
		psgDto.setCoachNo("3");
		psgDto.setSeatNo("12F");
		psgDto.setMobile("15618206323");



		dto.getPassengers().add(psgDto);

		psgDto = new TrainOrderPassengerDto();
		psgDto.setName("CICI/WANG");

		dto.getPassengers().add(psgDto);

		return dto;
	}

	public static FlightOrder createFlightOrder() {
		FlightOrder flightOrder = new FlightOrder();

		flightOrder.setEnterpriseId(ENTERPRISE_ID);
		flightOrder.setOrderNo(FLIGHT_ORDER_NO);

		FlightOrderPassenger psg = new FlightOrderPassenger();
		psg.setName(PASSENGER_NAME_CN);
		psg.setIdNo("360403");
		psg.setIdType(1);

		flightOrder.getPassengers().add(psg);


		FlightOrderFlight flt = new FlightOrderFlight();
		flt.getFlight().setFlightNo("MU888");
		flt.getFlight().setDepartureAirport("SHA");
		flt.getFlight().setArrivalAirport("KMG");
		flt.getFlight().setDepartureDate("2019-12-31");
		flt.getFlight().setSubclass("Y");

		flightOrder.getFlights().add(flt);


		flightOrder.setPsgCount(3);
		flightOrder.setAdultCount(1);
		flightOrder.setChildCount(1);
		flightOrder.setInfantCount(1);

		//成人价格
		flightOrder.setPrice(1000);
		flightOrder.setParvalue(1000);
		flightOrder.setTax(50);
		flightOrder.setServiceCharge(10);
		flightOrder.setCommission(5);

		//儿童价格
		flightOrder.setChdPrice(500);
		flightOrder.setChdParvalue(500);
		flightOrder.setChdTax(50);
		flightOrder.setChdServiceCharge(10);
		flightOrder.setChdCommission(0);

		//婴儿价格
		flightOrder.setInfPrice(100);
		flightOrder.setInfParvalue(100);
		flightOrder.setInfTax(0);
		flightOrder.setInfServiceCharge(10);
		flightOrder.setInfCommission(0);


		return flightOrder;
	}

	public static HotelOrder createHotelOrder() {
		HotelOrder hotelOrder = new HotelOrder();

		hotelOrder.setEnterpriseId(ENTERPRISE_ID);
		hotelOrder.setId(123);
		hotelOrder.setHotelId(100);
		hotelOrder.setRoomId(200);

		hotelOrder.setSupplierOrderStatus(1);
		hotelOrder.setSupplierOrderNo("S_ORDER_NO_123");

		return hotelOrder;
	}
}
